<?php

namespace App\Command\ResumeParsing\Service\ParsingSpecial;

use App\Command\ResumeParsing\Service\TranslateHelper;
use App\Service\FileHandler;
use EchoPHP\Facades\Log;

class Parsing51job extends ParsingSpecialXml {

    private $translateHelper;
    private $defaultAvatar = [];

    function __construct($helper) {
        parent::__construct($helper);
        $this->translateHelper = new TranslateHelper();

        $dir = __DIR__ . '/../Resource/DefaultAvatar/51Job';
        foreach (scandir($dir) as $fileName) {
            if (is_file($dir . '/' . $fileName)) $this->defaultAvatar[$fileName] = file_get_contents($dir . '/' . $fileName);
        }

        $this->get['template'] = function () {
            $this->listXPath("//templateTag[normalize-space()='templateTagName']");    //[contains(., 'templateTagName')][starts-with(normalize-space(), 'templateTagName')]
            $result = $this->xPath->query();
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent);
        };

        $this->get['id'] = function () {
            $tagName = 'ID:';
            //$this->listXPath("//table[@class='infr']/tr/td[starts-with(normalize-space(), '" . $tagName . "')]");
            $result = $this->xPath->query("//table[@class='infr']/tr/td[starts-with(normalize-space(), '" . $tagName . "')]");
            if ($result->length < 1) return '';
            return $this->preg_get('/(?<=' . $tagName . ')\s*(?<result>.*?)\s*(?=$)/u', $result[0]->textContent, array('groupName' => 'result'));
        };

        $this->get['time'] = function () {
            $tagName = '更新时间：';
            //$this->listXPath("/html/body/table/tr/td[starts-with(normalize-space(),'".$tagName."')]");
            $result = $this->xPath->query("/html/body/table/tr/td[starts-with(normalize-space(),'" . $tagName . "')]");
            if ($result->length < 1) return '';
            return $this->preg_get('/(?<=' . $tagName . ')\s*(?<result>.*?)\s*(?=$)/u', $result[0]->textContent, array('groupName' => 'result'));
        };

        $this->get['name'] = function () {
            //$this->listXPath("//table[@class='infr']/tr[contains(., 'ID:')]/td[@class='name']/text()[normalize-space()]");
            $result = $this->xPath->query("//table[@class='infr']/tr[contains(., 'ID:')]/td[@class='name']/text()[normalize-space()]");
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent);
        };

        $this->groupGetter['basic'] = array();

        $this->groupGetter['basic'][0] = function () {
            //$this->listXPath("/html/body/table/tr/td/table/tr/td/table/tr/td/table/tr/td[contains(., '男')]");
            $result = $this->xPath->query("//table[@class='infr']/tr[contains(., 'ID:')]/following-sibling::tr[2]/td");
            if ($result->length < 1) return '';
            return preg_split('/\s*\|\s*/u', $this->formatTxt($result[0]->textContent));
        };

        $this->groupGetter['basic'][] = function ($text) {
            $text = $this->formatTxt($text, TRUE);
            if (preg_match('/^[男女]$/u', $text)) {
                return array('sex' => $text);
            }
        };

        $this->groupGetter['basic'][] = function ($text) {
            $text = $this->formatTxt($text, TRUE);
            if (preg_match('/^(?<age>\d{2})岁(?:（(?<birthday>\d{4}年[01]?\d月[0123]?\d日)）)?$/u', $text, $matches)) {
                $result = array('age' => $matches['age'], 'birthday' => '');
                if (!empty($matches['birthday'])) $result['birthday'] = $this->func->formatDate($matches['birthday']);
                return $result;
            }
        };

        $this->groupGetter['basic'][] = function ($text) {
            $text = $this->formatTxt($text);
            if (preg_match('/^现居住\s*(?<workarea>.+)$/u', $text, $matches)) {
                return array('workarea' => $matches['workarea']);
            }
        };

        $this->groupGetter['basic'][] = function ($text) {
            $text = $this->formatTxt($text, TRUE);
            if (preg_match('/^(?:\d{1,2}\s*年(?:\s*[01]?\d\s*个?月)?|\d{1,2}\s*个?月)(?:\s*以上|\+)?(?=工作经验)/u', $text, $matches)) {
                return array('workyear' => $matches[0]);
            }
        };

        $this->get['sex'] = $this->groupGet('sex', 'basic');

        $this->get['nation'] = $this->tagNotExist;

        $this->get['identitycard'] = $this->tagNotExist;

        $this->groupGetter['contact'] = array();

        $this->groupGetter['contact'][0] = function () {
            //$this->listXPath("//table[@class='infr']/tr[contains(., 'ID:')]/following-sibling::tr[1]/td");
            $result = $this->xPath->query("//table[@class='infr']/tr[contains(., 'ID:')]/following-sibling::tr[1]/td");
            if ($result->length < 1) return '';
            return $result;
        };

        $this->groupGetter['contact'][] = function ($td) {
            $text = $this->formatTxt($td->textContent, TRUE);
            if (isset($this->translateHelper->dictCurrentSituation[$text])) {
                return array('current_situation' => $text);
            }
        };

        $this->groupGetter['contact'][] = function ($td) {
            $text = $this->formatTxt($td->textContent, TRUE);
            if (preg_match('/^1\d{10}$/', $text)) {
                return array('mobile' => $text);
            }
        };

        $this->groupGetter['contact'][] = function ($td) {
            $text = $this->formatTxt($td->textContent, TRUE);
            if (preg_match('/^\S+@[\w\-]+\.\S+$/', $text)) {
                return array('email' => $text);
            }
        };

        $this->get['mobile'] = $this->groupGet('mobile', 'contact');

        $this->get['email'] = $this->groupGet('email', 'contact');

        $this->get['age'] = $this->groupGet('age', 'basic');

        $this->get['married'] = function () {
            //$this->listXPath("//tr[td[@class='plate1' and normalize-space()='个人信息']]/following-sibling::tr/td/table/tbody/tr/td/table/tbody/tr/td[@class='keys' and normalize-space()='婚姻状况：']/following-sibling::td[@class='txt2'][1]");
            $result = $this->xPath->query("//tr[td[@class='plate1' and normalize-space()='个人信息']]/following-sibling::tr/td/table/tbody/tr/td/table/tbody/tr/td[@class='keys' and normalize-space()='婚姻状况：']/following-sibling::td[@class='txt2'][1]");
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent, 'space');
        };

        $this->get['politic'] = function () {
            //$this->listXPath("//tr[td[@class='plate1' and normalize-space()='个人信息']]/following-sibling::tr/td/table/tbody/tr/td/table/tbody/tr/td[@class='keys' and normalize-space()='政治面貌：']/following-sibling::td[@class='txt2'][1]");
            $result = $this->xPath->query("//tr[td[@class='plate1' and normalize-space()='个人信息']]/following-sibling::tr/td/table/tbody/tr/td/table/tbody/tr/td[@class='keys' and normalize-space()='政治面貌：']/following-sibling::td[@class='txt2'][1]");
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent, 'space');
        };

        $this->get['degree'] = function () {
            //$this->listXPath("//tr[td[@class='plate2' and contains(.,'最高') and (contains(.,'学历') or contains(.,'学位'))]]/following-sibling::tr/td[@class='keys' and (contains(.,'学历') or contains(.,'学位')) and contains(.,'：')][1]/following-sibling::td[@class='txt2'][1]");
            $result = $this->xPath->query("//tr[td[@class='plate2' and contains(.,'最高') and (contains(.,'学历') or contains(.,'学位'))]]/following-sibling::tr/td[@class='keys' and (contains(.,'学历') or contains(.,'学位')) and contains(.,'：')][1]/following-sibling::td[@class='txt2'][1]");
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent, 'space');
        };

        $this->get['industry'] = function () {
            //$this->listXPath("/html/body/table/tr/td/table/tr/td/table/tr/td/table/tr/td/table/tbody/tr/td[normalize-space()='行　业：']/following-sibling::td[@class='txt2'][1]");
            $result = $this->xPath->query("/html/body/table/tr/td/table/tr/td/table/tr/td/table/tr/td/table/tbody/tr/td[normalize-space()='行　业：']/following-sibling::td[@class='txt2'][1]");
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent, 'space');
        };

        $this->get['position'] = function () {
            //$this->listXPath("//tr[td[normalize-space()='求职意向']]/following-sibling::tr/td/table/tr/td/table/tbody/tr/td[@class='keys' and (contains(.,'职能') or contains(.,'职位')) and contains(.,'：')][1]/following-sibling::td[@class='txt2'][1]");
            $result = $this->xPath->query("//tr[td[@class='plate1' and normalize-space()='求职意向']]/following-sibling::tr/td/table/tr/td/table/tbody/tr/td[@class='keys' and (contains(.,'职能') or contains(.,'职位')) and contains(.,'：')][1]/following-sibling::td[@class='txt2'][1]");
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent, 'space');
        };

        $this->get['career'] = $this->tagNotExist;

        $this->get['major'] = function () {
            //$this->listXPath("//tr[td[@class='plate2' and contains(.,'最高') and (contains(.,'学历') or contains(.,'学位'))]]/following-sibling::tr/td[@class='keys' and contains(.,'专') and contains(.,'业') and contains(.,'：')][1]/following-sibling::td[@class='txt2'][1]");
            $result = $this->xPath->query("//tr[td[@class='plate2' and contains(.,'最高') and (contains(.,'学历') or contains(.,'学位'))]]/following-sibling::tr/td[@class='keys' and contains(.,'专') and contains(.,'业') and contains(.,'：')][1]/following-sibling::td[@class='txt2'][1]");
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent, 'space');
        };

        $this->get['birthday'] = $this->groupGet('birthday', 'basic');

        $this->get['workyear'] = $this->groupGet('workyear', 'basic');

        $this->get['workarea'] = $this->groupGet('workarea', 'basic');

        $this->get['expectarea'] = function () {
            //$this->listXPath("//tr[normalize-space()='求职意向']/following-sibling::tr/td/table/tr/td/table/tbody/tr/td[normalize-space()='地点：']/following-sibling::td[@class='txt2'][1]");
            $result = $this->xPath->query("//tr[td[@class='plate1' and normalize-space()='求职意向']]/following-sibling::tr/td/table/tr/td/table/tbody/tr/td[@class='keys' and normalize-space()='地点：']/following-sibling::td[@class='txt2'][1]");
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent, 'space');
        };

        $this->get['area'] = function () {
            //$this->listXPath("//tr[td[@class='plate1' and normalize-space()='个人信息']]/following-sibling::tr/td/table/tbody/tr/td/table/tbody/tr/td[@class='keys' and contains(.,'户口') and contains(.,'：')]/following-sibling::td[@class='txt2'][1]");
            $result = $this->xPath->query("//tr[td[@class='plate1' and normalize-space()='个人信息']]/following-sibling::tr/td/table/tbody/tr/td/table/tbody/tr/td[@class='keys' and contains(.,'户口') and contains(.,'：')]/following-sibling::td[@class='txt2'][1]");
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent, 'space');
        };

        $this->get['salary'] = function () {
            //$this->listXPath("//tr/td[@class='plate1' and starts-with(normalize-space(), '目前年收入：')]/span[@class='f16'][1]");
            $result = $this->xPath->query("//tr/td[@class='plate1' and starts-with(normalize-space(), '目前年收入：')]/span[@class='f16'][1]");
            if ($result->length < 1) return '';
            $resultText = $this->formatTxt($result[0]->textContent);
            $salary = $this->func->parseSalary($resultText, 'annual');
            if (count($salary)) {
                $this->helper->resumeInfo['salaryfrom'] = $salary['monthly']['begin'];
                $this->helper->resumeInfo['salaryend'] = $salary['monthly']['end'];
                //$this->helper->resumeInfo['salaryafrom'] = $salary['annual']['begin'];
                //$this->helper->resumeInfo['salaryaend'] = $salary['annual']['end'];
            }
            return $resultText;
        };

        $this->get['expectsalary'] = function () {
            //$this->listXPath("//tr[td[@class='plate1' and normalize-space()='求职意向']]/following-sibling::tr/td/table/tr/td/table/tbody/tr/td[@class='keys' and normalize-space()='期望薪资：']/following-sibling::td[@class='txt2'][1]");
            $result = $this->xPath->query("//tr[td[@class='plate1' and normalize-space()='求职意向']]/following-sibling::tr/td/table/tr/td/table/tbody/tr/td[@class='keys' and normalize-space()='期望薪资：']/following-sibling::td[@class='txt2'][1]");
            if ($result->length < 1) return '';
            $resultText = $this->formatTxt($result[0]->textContent);
            $expectsalary = $this->func->parseSalary($resultText);
            if (count($expectsalary)) {
                $this->helper->resumeInfo['expectsalaryfrom'] = $expectsalary['monthly']['begin'];
                $this->helper->resumeInfo['expectsalaryend'] = $expectsalary['monthly']['end'];
                //$this->helper->resumeInfo['expectsalaryafrom'] = $expectsalary['annual']['begin'];
                //$this->helper->resumeInfo['expectsalaryaend'] = $expectsalary['annual']['end'];
            }
            return $resultText;
        };

        $this->get['jobterm'] = function () {
            //$this->listXPath("//tr[normalize-space()='求职意向']/following-sibling::tr/td/table/tr/td/table/tbody/tr/td[normalize-space()='工作类型：']/following-sibling::td[@class='txt2'][1]");
            $result = $this->xPath->query("//tr[normalize-space()='求职意向']/following-sibling::tr/td/table/tr/td/table/tbody/tr/td[normalize-space()='工作类型：']/following-sibling::td[@class='txt2'][1]");
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent, true);
        };

        $this->get['entrytime'] = function () {
            //$this->listXPath("//tr[td[normalize-space()='求职意向']]/following-sibling::tr/td/table/tr/td/table/tbody/tr/td[normalize-space()='到岗时间：'][1]/following-sibling::td[@class='txt2'][1]");
            $result = $this->xPath->query("//tr[td[normalize-space()='求职意向']]/following-sibling::tr/td/table/tr/td/table/tbody/tr/td[normalize-space()='到岗时间：'][1]/following-sibling::td[@class='txt2'][1]");
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent, true);
        };

        $this->get['current_situation'] = $this->groupGet('current_situation', 'contact');

        $this->get['school'] = function () {
            //$this->listXPath("//tr[td[@class='plate2' and contains(.,'最高') and (contains(.,'学历') or contains(.,'学位'))]]/following-sibling::tr/td[@class='keys' and contains(.,'学') and contains(.,'校') and contains(.,'：')][1]/following-sibling::td[@class='txt2'][1]");
            $result = $this->xPath->query("//tr[td[@class='plate2' and contains(.,'最高') and (contains(.,'学历') or contains(.,'学位'))]]/following-sibling::tr/td[@class='keys' and contains(.,'学') and contains(.,'校') and contains(.,'：')][1]/following-sibling::td[@class='txt2'][1]");
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent, 'space');
        };

        $this->get['nofocuse'] = $this->tagNotExist;

        $this->groupGetter['work'] = array();

        $this->groupGetter['work'][0] = function ($work) {
            return $this->xPath->query("tbody/tr", $work);
        };

        $this->groupGetter['work'][] = function ($tr) {
            $timeNode = $this->xPath->query("td[@class='time']", $tr);
            $companyNode = $this->xPath->query("td[contains(@class, 'rtbox')]", $tr);
            if ($timeNode->length && $companyNode->length) {
                $time = $this->formatTxt($timeNode[0]->textContent, TRUE);
                $tmp = $this->func->parseTimespan($time);
                $result = array('time' => $time, 'time_from' => $tmp['begin'], 'time_end' => $tmp['end']);
                $timespanNode = $this->xPath->query("span[@class='gray']", $companyNode[0]);
                $companyNode = $this->xPath->query("span[@class='bold']", $companyNode[0]);
                if ($companyNode->length) $result['company'] = $this->formatTxt($companyNode[0]->textContent, TRUE);
                if ($timespanNode->length) $result['comment'] = '工作时间：' . $this->preg_get('/\(\s*(?<result>.*)\s*\)/u', $this->formatTxt($timespanNode[0]->textContent, TRUE));
                return $result;
            }
        };

        $this->groupGetter['work'][] = function ($tr) {
            $text = $this->formatTxt($tr->textContent);
            if (!empty($industryArr = $this->translateHelper->getIndustryCode($text, false, true))) {
                $result = ['industry' => array_key_first($industryArr)];
                $text = str_replace($result['industry'], '', $text);
                $text = preg_replace('/(?:\s*\|\s*){2,}/u', ' | ', $text);
                $text = trim($text, " \t\n\r\0\x0B|");
                if (!empty($text)) $result['comment'] = $this->formatTxt($text, true);
                return $result;
            }
        };

        $this->groupGetter['work'][] = function ($tr) {
            $timeNode = $this->xPath->query("td[@class='time']", $tr);
            $dutyNode = $this->xPath->query("td[contains(@class, 'rtbox')]", $tr);
            if ($timeNode->length && !empty($this->formatTxt($timeNode[0]->textContent, TRUE)) && $dutyNode->length) {
                return array('duty' => $this->formatTxt($dutyNode[0]->textContent, TRUE), 'comment' => $this->formatTxt($timeNode[0]->textContent, TRUE));
            }
        };

        $this->groupGetter['work'][] = function ($tr) {
            $text = preg_replace('/^工作描述\s*：\s*/u', '', $this->formatTxt($tr->textContent), -1, $count);
            if ($count) return ['comment' => $text];
        };

        $this->get['workinfo'] = function () {
            //$this->listXPath("//tr[td[@class='plate1' and normalize-space()='工作经验']]/following-sibling::tr/td/table/tr/td/table");
            $result = $this->xPath->query("//tr[td[@class='plate1' and normalize-space()='工作经验']]/following-sibling::tr/td/table/tr/td/table");
            if ($result->length < 1) return '';
            $data = array();

            foreach ($result as $table) {
                $data[] = $this->groupProcess('work', $table);
            }
            return $data;
        };

        $this->groupGetter['project'] = array();

        $this->groupGetter['project'][0] = function ($project) {
            return $this->xPath->query("tr", $project);
        };

        $this->groupGetter['project'][] = function ($tr) {
            $timeNode = $this->xPath->query("td[@class='time']", $tr);
            $projectNode = $this->xPath->query("td[contains(@class, 'rtbox')]", $tr);
            if ($timeNode->length && $projectNode->length) {
                $time = $this->formatTxt($timeNode[0]->textContent, TRUE);
                $tmp = $this->func->parseTimespan($time);
                return array('time' => $time, 'time_from' => $tmp['begin'], 'time_end' => $tmp['end'], 'project' => $this->formatTxt($projectNode[0]->textContent, TRUE));
            }
        };

        $this->groupGetter['project'][] = function ($tr) {
            $tdArr = $this->xPath->query("td/table/tbody/tr/td[@class='keys' and normalize-space()='所属公司：']/following-sibling::td[@class='txt1']", $tr);
            if ($tdArr->length) {
                return array('company' => $this->formatTxt($tdArr[0]->textContent, TRUE));
            }
        };

        $this->groupGetter['project'][] = function ($tr) {
            $text = preg_replace('/^项目描述\s*：\s*/u', '', $this->formatTxt($tr->textContent), -1, $count);
            if ($count) return ['comment' => $text];
        };

        $this->get['projectinfo'] = function () {
            //$this->listXPath("//tr[td[@class='plate1' and normalize-space()='项目经验']]/following-sibling::tr/td/table/tr/td/table");
            $result = $this->xPath->query("//tr[td[@class='plate1' and normalize-space()='项目经验']]/following-sibling::tr/td/table/tr/td/table");
            if ($result->length < 1) return '';
            $data = array();

            foreach ($result as $table) {
                $data[] = $this->groupProcess('project', $table);
            }
            return $data;
        };

        $this->groupGetter['education'] = array();

        $this->groupGetter['education'][0] = function ($education) {
            return $trArr = $this->xPath->query("tr", $education);
        };

        $this->groupGetter['education'][] = function ($tr) {
            $tdArr = $this->xPath->query("td", $tr);
            if ($tdArr->length && $tdArr[0]->attributes->getNamedItem('class')->value == 'time' && $tdArr[1]->attributes->getNamedItem('class')->value == 'rtbox') {
                $time = $this->formatTxt($tdArr[0]->textContent);
                $tmp = $this->func->parseTimespan($time);
                return array('time' => $this->formatTxt($tdArr[0]->textContent), 'time_from' => $tmp['begin'], 'time_end' => $tmp['end'], 'school' => $this->formatTxt($tdArr[1]->textContent));
            }
        };

        $this->groupGetter['education'][] = function ($tr) {
            $result = $this->xPath->query("td[@class='txt1'][1]", $tr);
            if ($result->length) {
                $arr = preg_split('/\s*\|\s*/u', $this->formatTxt($result[0]->textContent, TRUE));
                if (count($arr) == 2) return array('degree' => $arr[0], 'major' => $arr[1]);
            }
        };

        $this->get['educationinfo'] = function () {
            //$this->listXPath("//tr[td[@class='plate1' and normalize-space()='教育经历']]/following-sibling::tr/td/table/tbody/tr/td/table");
            $result = $this->xPath->query("//tr[td[@class='plate1' and normalize-space()='教育经历']]/following-sibling::tr/td/table/tbody/tr/td/table");
            if ($result->length < 1) return '';
            $data = array();
            foreach ($result as $table) {
                $data[] = $this->groupProcess('education', $table);
            }
            return $data;
        };

        $this->get['skillinfo'] = function () {
            //$this->listXPath("//tr[td[@class='plate1' and starts-with(normalize-space(), '技能特长')]]/following-sibling::tr[1]//tr[td[@class='tit' and contains(.,'技能')]]/following-sibling::tr[1]//td[@class='tb2 cell']");
            $result = $this->xPath->query("//tr[td[@class='plate1' and starts-with(normalize-space(), '技能特长')]]/following-sibling::tr[1]//tr[td[@class='tit' and contains(.,'技能')]]/following-sibling::tr[1]//td[@class='tb2 cell']");
            $resultText = '';
            foreach ($result as $item) {
                $resultText .= "\r\n" . $this->formatTxt($item->textContent, 'space');
            }
            return trim($resultText);
        };

        $this->get['awardinfo'] = function () {
            //$this->listXPath("//tr[td[@class='plate1' and starts-with(normalize-space(), '在校情况')]]/following-sibling::tr//tr[td[@class='tit' and contains(.,'荣誉')]]/following-sibling::tr[1]//tr[td[@class='time']]");
            $result = $this->xPath->query("//tr[td[@class='plate1' and starts-with(normalize-space(), '在校情况')]]/following-sibling::tr//tr[td[@class='tit' and contains(.,'荣誉')]]/following-sibling::tr[1]//tr[td[@class='time']]");
            $resultText = '';
            foreach ($result as $item) {
                $resultText .= "\r\n" . $this->formatTxt($item->textContent, 'space');
            }
            return trim($resultText);
        };

        $this->get['commentinfo'] = function () {
            //$this->listXPath("//tr[td[@class='plate1' and normalize-space()='求职意向']]/following-sibling::tr/td/table/tr/td/table/tbody/tr/td[@class='keys' and normalize-space()='自我评价：']/following-sibling::td[@class='txt1'][1]");
            $result = $this->xPath->query("//tr[td[@class='plate1' and normalize-space()='求职意向']]/following-sibling::tr/td/table/tr/td/table/tbody/tr/td[@class='keys' and normalize-space()='自我评价：']/following-sibling::td[@class='txt1'][1]");
            if ($result->length < 1) return '';
            return $this->formatTxt($result[0]->textContent);
        };

        $this->get['otherinfo'] = function () {
            $otherInfo = $this->groupCache['comment'];
            //$this->listXPath("//tr[td[@class='plate1' and starts-with(normalize-space(), '技能特长')]]/following-sibling::tr[1]//tr[td[@class='tit' and contains(.,'证书')]]/following-sibling::tr[1]//tr[td[@class='time']]");
            foreach (['证书', '培训经历'] as $title) {
                $result = $this->xPath->query("//tr[td[@class='plate1' and starts-with(normalize-space(), '技能特长')]]/following-sibling::tr[1]//tr[td[@class='tit' and contains(.,'" . $title . "')]]/following-sibling::tr[1]//tr[td[@class='time']]");
                if (count($result)) {
                    $otherInfo .= "\r\n\r\n" . $title;
                    foreach ($result as $item) {
                        $otherInfo .= "\r\n" . $this->formatTxt($item->textContent, 'space');
                    }
                }
            }
            //$this->listXPath("/html/body/table/tr/td/table/tr/td/table/tr/td/table/tr[starts-with(normalize-space(), '附加信息')]/following-sibling::tr");
            $result = $this->xPath->query("/html/body/table/tr/td/table/tr/td/table/tr/td/table/tr[starts-with(normalize-space(), '附加信息')]/following-sibling::tr");
            if ($result->length) $otherInfo .= "\r\n\r\n" . $this->formatTxt(preg_replace('/▲\s*/u', '', $result[0]->textContent));
            return trim($otherInfo);
        };

        $this->get['avatar'] = function () {
            try {
                //$this->listXPath("//td[table[@class='infr']/tr[contains(., 'ID:')]/td[@class='name']][1]/preceding-sibling::td//img/@src");
                $result = $this->xPath->query("//td[table[@class='infr']/tr[contains(., 'ID:')]/td[@class='name']][1]/preceding-sibling::td//img/@src");
                if (!count($result) || empty($internalPath = $result[0]->textContent)) return '';
                if (empty($this->helper->resume['resumeImage']) || empty($this->helper->resume['resumeImage'][$internalPath])) return '';
                $imgInfo = $this->helper->resume['resumeImage'][$internalPath];
                if (in_array($imgInfo['data'], $this->defaultAvatar)) return '';

                return ['data' => &$imgInfo['data'], 'name' => str_replace(':', '_', $internalPath) . $this->func->mime2Ext($imgInfo['mime'])];
            } catch (\Exception $e) {
                Log::error(e_dump($e), ['avatar' => $internalPath ?? ''], 'cmd');
                return '';
            }
        };
    }
}
